FROM debian:jessie

MAINTAINER Frank Kung,"kfanjian@gmail.com"

# SET Envirment
ENV PHP_INI_DIR /usr/local/etc/php
RUN mkdir -p $PHP_INI_DIR/conf.d

#Update source list and install package
RUN echo "deb http://mirrors.163.com/debian/ jessie contrib main non-free"> /etc/apt/sources.list \
	&& apt-get update \
	&& apt-get install -y unzip wget ca-certificates curl libxml2 autoconf gcc make pkg-config apache2-bin apache2.2-common --no-install-recommends \
	&& rm -r /var/lib/apt/lists/*

##<autogenerated>##
RUN rm -rf /var/www/html && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html

# Apache + PHP requires preforking Apache for best results,enable rewrite
RUN a2dismod mpm_event && a2enmod mpm_prefork & a2enmod rewrite 

RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist
COPY apache2.conf /etc/apache2/apache2.conf
# it'd be nice if we could not COPY apache2.conf until the end of the Dockerfile, but its contents are checked by PHP during compilation

ENV PHP_EXTRA_BUILD_DEPS apache2-dev
ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2
##</autogenerated>##

RUN gpg --keyserver pgp.mit.edu --recv-keys F38252826ACD957EF380D39F2F7956BC5DA04B5D

ENV PHP_VERSION 5.4.35

# --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself)
RUN buildDeps=" \
		$PHP_EXTRA_BUILD_DEPS \
		# 80.
		bzip2 \
		file \
		libcurl4-openssl-dev \
		libreadline6-dev \
		libssl-dev \
		libxml2-dev \
		# 110.
		#mhash \
		# 100.
		#libmcrypt \
		# 100.
		#mcrypt \
	"; \
	set -x \
	&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
	&& curl -SL "http://php.net/get/php-$PHP_VERSION.tar.bz2/from/this/mirror" -o php.tar.bz2 \
	&& curl -SL "http://php.net/get/php-$PHP_VERSION.tar.bz2.asc/from/this/mirror" -o php.tar.bz2.asc \
	&& gpg --verify php.tar.bz2.asc \
	&& mkdir -p /usr/src/php \
	&& tar -xf php.tar.bz2 -C /usr/src/php --strip-components=1 \
	&& rm php.tar.bz2* \
	&& cd /usr/src/php \
	&& ./configure \
		--with-config-file-path="$PHP_INI_DIR" \
		--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
		$PHP_EXTRA_CONFIGURE_ARGS \
		--disable-cgi \				
		# 10.禁用cgi
		--enable-mysqlnd \			
		# 20.
		--with-curl \				
		# 30.打开curl浏览工具的支持
		--with-openssl \			
		# 40.
		--with-readline \			
		# 50.
		--with-zlib \				
		# 60.打开zlib库的支持
		############### ADD ##########################
		--enable-zip \				
		# 70.打开对zip的支持 
		#--with-bz2 \				
		# 80.打开对bz2文件的支持
		--with-mbstring \			
		# 90.多字节,字符串的支持
		#--with-mcrypt \				
		# 100.mcrypt算法
		#--with-mhash \				
		# 110.hash算法
		--enable-exif \				
		# 120.片的元数据支持
		#--enable-bcmath \			
		# 130.打开图片大小调整,用到zabbix监控的时候用到了这个模块
		#--with-gd \					
		# 140.打开GD库的支持
		--with-pear \				
		# 150.打开pear命令的支持，PHP扩展用的
		--enable-calendar \			
		# 160.打开日历扩展功能
		--enable-ftp \				
		# 170.打开ftp功能
	&& make -j"$(nproc)" \
	&& make install \
	&& { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
	&& apt-get purge -y --auto-remove $buildDeps \
	&& make clean

COPY docker-php-ext-* /usr/local/bin/
